<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Created by PhpStorm.
 * Date: 2018/9/13
 * Time: 下午6:44
 */
class c_data extends CI_Controller{

    function index()
    {
        $this->load->view('bacteria/v_success');
    }
    function queryById($image_id){
        $this->load->model('m_bacteria');
//        $data['image'] = $this->m_bacteria->queryById($image_id);
//        $this->load->model('m_image');
//        $data['image']=$this->m_image->queryById(1,$bac_id);
        $this->load->view('bacteria/v_front_bacteria',$data);
    }
    function add_post(){
        if ($_POST["session_add"]!=null){
            $this->load->view('bacteria/v_bac_add');
        }
    }
    function update_post($bac_id)
    {
        if ($_POST["session_update"] != null) {
            $this->load->model('m_bacteria');
            $data['result'] = $this->m_bacteria->queryById($bac_id);
            $this->load->view('bacteria/v_bac_update', $data);
        }
    }
    function update($image_id){
        $this->load->model('m_bacteria');

        $modify_time=date('Y-m-d');
        if($_POST!=null&&$_POST["submit"]) {
            $image_name = $_POST["image_name"];
            $image_Latin_name = $_POST["image_Latin_name"];
            $image_data = $_POST["image_data"];
            $arr = array(
                'image_name' => $image_name,
                'image_Latin_name' => $image_Latin_name,
                'image_data' => $image_data );

            $update = $this->m_bacteria->update($image_id, $arr);
            redirect('c_data/');
        }
    }
    function updatespec($specimen_id){
        $this->load->model('m_bacteria');

        $modify_time=date('Y-m-d');
        if($_POST!=null&&$_POST["submit"]) {
            $specimen_name = $_POST["specimen_name"];
            $specimen_latin = $_POST["specimen_latin"];
            $specimen_no = $_POST["specimen_no"];
            $specimen_time = $_POST["specimen_time"];
            $specimen_source = $_POST["specimen_source"];
            $specimen_message = $_POST["specimen_message"];
            $specimen_save = $_POST["specimen_save"];
            $specimen_drug = $_POST["specimen_drug"];
            $specimen_serum = $_POST["specimen_serum"];
            $specimen_virulence = $_POST["specimen_virulence"];
            $specimen_molecule = $_POST["specimen_molecule"];
            $specimen_result = $_POST["specimen_result"];
            $arr = array(
                'specimen_name' => $specimen_name,
                'specimen_latin' => $specimen_latin,
                'specimen_no' => $specimen_no,
                'specimen_time' => $specimen_time,
                'specimen_source' => $specimen_source,
                'specimen_message' => $specimen_message,
                'specimen_save' => $specimen_save,
                'specimen_drug' => $specimen_drug,
                'specimen_serum' => $specimen_serum,
                'specimen_virulence' => $specimen_virulence,
                'specimen_molecule' => $specimen_molecule,
                'specimen_result' => $specimen_result );

            $update = $this->m_bacteria->updatespec($specimen_id, $arr);
            redirect('c_specimen_admin/');
            //$this->load->view('bacteria/v_specimen_info_admin');
            //return true;
        }
    }
    function addspec(){
        $this->load->model('m_bacteria');

        $modify_time=date('Y-m-d');
        if($_POST!=null&&$_POST["submit"]) {
            $specimen_name = $_POST["specimen_name"];
            $specimen_latin = $_POST["specimen_latin"];
            $specimen_no = $_POST["specimen_no"];
            $specimen_time = $_POST["specimen_time"];
            $specimen_source = $_POST["specimen_source"];
            $specimen_message = $_POST["specimen_message"];
            $specimen_save = $_POST["specimen_save"];
            $specimen_drug = $_POST["specimen_drug"];
            $specimen_serum = $_POST["specimen_serum"];
            $specimen_virulence = $_POST["specimen_virulence"];
            $specimen_molecule = $_POST["specimen_molecule"];
            $specimen_result = $_POST["specimen_result"];
            $arr = array(
                'specimen_name' => $specimen_name,
                'specimen_latin' => $specimen_latin,
                'specimen_no' => $specimen_no,
                'specimen_time' => $specimen_time,
                'specimen_source' => $specimen_source,
                'specimen_message' => $specimen_message,
                'specimen_save' => $specimen_save,
                'specimen_drug' => $specimen_drug,
                'specimen_serum' => $specimen_serum,
                'specimen_virulence' => $specimen_virulence,
                'specimen_molecule' => $specimen_molecule,
                'specimen_result' => $specimen_result );

            $update = $this->m_bacteria->addspec($arr);
            redirect('c_specimen_admin/');
            //$this->load->view('bacteria/v_specimen_info_admin');
            //return true;
        }
    }

    function dataupdate($data_id){
        $this->load->model('m_bacteria');

        $modify_time=date('Y-m-d');
        if($_POST!=null&&$_POST["submit"]) {
            $data_m_z = $_POST["data_m_z"];
            $data_peak_height = $_POST["data_peak_height"];
            $data_peak_area = $_POST["data_peak_area"];
            $data_signal_noise_ratio = $_POST["data_signal_noise_ratio"];
            $data_image_resolution = $_POST["data_image_resolution"];

            $arr = array(
                'data_m_z' => $data_m_z,
                'data_peak_height' => $data_peak_height,
                'data_peak_area' => $data_peak_area,
                'data_signal_noise_ratio' => $data_signal_noise_ratio,
                'data_image_resolution' => $data_image_resolution);

            $update = $this->m_bacteria->dataupdate($data_id, $arr);
            redirect('c_data/');
        }
    }
    function delete($bac_id){
        $user_id=$_POST['session_user_id'];
        $bac_modify_time=date('Y-m-d');
        $this->load->model('m_bacteria');
        $delete=$this->m_bacteria->in_recycle($bac_id,$user_id,$bac_modify_time);
        //$this->index();
        redirect('c_data');
    }
    function getPost(){
//        if($_POST) {
//            $keywords = $_POST['keywords'];     //查询值
//            //用来存放查询方式（对应表中的属性名）
//        }
//        $this->queryFind(urldecode($keywords),0);
        //echo $keywords;
        //echo $selecttype;
    }

    function queryFind($keywords,$page){
        $search = 1;    //通过search将数据查询分为搜索和分页查询

        $page = (int) $page;
        $segments['keywords']  = urldecode($keywords);
        $data['segments'] = $segments;
        $search_url = $segments['keywords'];

        $options['keywords'] = $segments['keywords'];

        $data['temp'] =array(
            'keywords'=>  $options['keywords'],
            'search'=> 1,
            'page'=> $page
        ) ;
        $data['options'] = $options;
        $data['keywords'] = $segments['keywords'];

        //print_r($data['options']);
        //分页开始的数据行:$page_offset
        if($page)
        {
            $page_offset = $page ;
        }
        else if(!empty($segments['page']))
        {
            $page_offset = (int) $segments['page'];
        }
        else
        {
            $page_offset = 0;
        }
        if($page_offset < 0)
        {
            $page_offset = 0;
        }

        //分页url
        $this->load->helper('url');

        $base_url = site_url('c_data/queryFind').'/';

        //每页显示条数
        $per_page = 15;

        //数据总数
        $this->load->model('m_bacteria');
        $data['total_rows'] = $this->m_bacteria->getDataCount($options);

        //总页数
        $data['total_pages'] = ceil($data['total_rows'] / $per_page);

        //当前页(input)
        $data['page'] = $page_offset+1;
        $data['page'] = ($data['page']>$data['total_pages'] && $data['total_pages']>0) ? $data['total_pages'] : $data['page'];
       // print_r($data['page']);
        //第一页   最后一页   前一页   后一页
        $data['page_first'] = $base_url.$search_url.'/0';
        $data['page_last'] = $base_url.$search_url.'/'.($data['total_pages'] - 1);
        $data['page_prev'] = ($data['page'] > 1) ? $base_url.$search_url.'/'.($data['page']-2) : $data['page_first'];
        $data['page_next'] = ($data['page'] < $data['total_pages']) ? $base_url.$search_url.'/'.($data['page']) : $data['page_last'];
        //$data['page_next'] = ($data['page'] < $data['total_pages']) ? $base_url.($data['page']).$search_url : $data['page_last'];
        //当前页
        $data['cur_page'] = $base_url.$search_url.'/'.($data['page'] - 1);

        //当前页起始数据号码
        $data['show_start'] = ($data['page'] - 1)*$per_page +1;

        //当前页结束数据号
        $data['show_end'] = ($page_offset < $data['total_pages'] - 1) ? ($data['show_start'] + $per_page - 1) : $data['total_rows'];

        //图书结果集
        $bac_del = 1;
        $data['bacteria'] = $this->m_bacteria->find_bacteria($options,$per_page,($data['page'] - 1)*$per_page,$bac_del);
        //print_r($options);
        //$options,$count=20, $offset=0, $is_delete=0
        $data['select'] = array('count'=>$per_page,'offset'=>($data['page'] - 1)*$per_page,'bac_del'=>$bac_del);

        // ajax
        // if(!empty($segments['ajax']) || $search == 1)
        //{
        //echo "209";
        if(@$_SESSION['role_id']==1){
            $this->load->view('bacteria/v_data',$data);
            //print_r(@$_SESSION);
        } else
            $this->load->view('bacteria/v_data_low',$data);
        //}
        // 非 ajax
    }
    function img_upload($idmax){
//        header("Content-type:text/html;charset=gbk");
        $config['upload_path']='./image/';
        $config['allowed_types']='*';
        //$config['max_size']=2048;
        //$config['max_width']=2048;
        //$config['max_height']=2048
        $this->load->library('upload',$config);

        if ($this->upload->do_upload('userfile'))
        {
            $data = array('upload_data' => $this->upload->data());
            $name=$data['upload_data']['orig_name'];
//            $name=iconv("utf-8","gbk",$data['upload_data']['orig_name']);
//            echo "Upload: " . iconv("utf-8","gbk",$data['upload_data']['orig_name'])  . "<br />";
            $namearray = explode("-",$name);
//            echo $namearray[0] ."<br />";
//            echo $namearray[1];
//            echo "ssssssssss";
            if(sizeof($namearray)>1){
                $arr = array(
//                    'image_id'=>$idmax+1,
                    'image_path'=>'image/'.$data['upload_data']['orig_name'],
                    'image_data'=>$namearray[2],
                    'image_Latin_name'=>$namearray[1],
                    'image_name'=>$namearray[0]);
                $this->load->model('m_image');
                $this->m_image->insert($arr);
                $this->load->view('bacteria/v_success');}
            else
            {
                $this->load->view('bacteria/v_fail');
            }
        }
//            redirect('c_data/');
        else
        {
           
           $this->load->view('bacteria/v_fail');
        }

    }

    function img_uploadspec(){
        $config['upload_path']='./image/';
        $config['allowed_types']='*';
        $this->load->library('upload',$config);
        if ($this->upload->do_upload('userfile'))
        {
            $data = array('upload_data' => $this->upload->data());
            $name=$data['upload_data']['orig_name'];
//            $name=iconv("utf-8","gbk",$data['upload_data']['orig_name']);
//            echo "Upload: " . iconv("utf-8","gbk",$data['upload_data']['orig_name'])  . "<br />";
            $namearray = explode("-",$name);
            if(sizeof($namearray)<3){
                redirect('c_specimen_admin/');}
            else
            {
                echo "11";
                $this->load->view('bacteria/v_fail');
            }
         }
        else
        {
           
           $this->load->view('bacteria/v_specimen_fail');
        }
    }

    function file_upload($image_id){
        $config['upload_path']='./bac_files/';
        $config['allowed_types']='*';
        //$config['max_size']=2048;
        //$config['max_width']=2048;
        //$config['max_height']=2048;

        $this->load->library('upload',$config);
        if ($this->upload->do_upload('userfile'))
        {
            $data = array('upload_data' => $this->upload->data());
            $file_up_time=date('Y-m-d');
            $arr = array(
                '$image_id'=>$image_id,
                'file_status'=>1,
                'file_part'=>1,
                'file_path'=>'bac_files/'.$data['upload_data']['orig_name'],
                'file_descript' => $_POST["file_descript"],
                'file_name'=>$data['upload_data']['orig_name'],
                'file_up_time'=>$file_up_time);
            $this->load->model('m_file');
//            $this->m_file->insert($arr);
            redirect('c_data/');
        }
//        else
//        {
//            $error = array('error' => $this->upload->display_errors());
//            print_r($error);
//            $this->load->view('v_login');
//
//        }
    }
    function delete_image($image_id){
        $this->load->model('m_image');
        $bac_id=$_POST['session_bac_id'];
        $delete=$this->m_image->in_recycle($image_id);
        //$this->index();
        redirect('c_data/queryById/'.$bac_id);
    }
    function delete_file($file_id){
        $bac_id=$_POST['session_bac_id'];
        $this->load->model('m_file');
        $delete=$this->m_file->in_recycle($file_id);
        //$this->index();
        redirect('c_data/queryById/'.$bac_id);
    }

    function vdownload($image_id){
        $data['image_id']=$image_id;
        $this->load->view('bacteria/v_download',$data);
    }
    function vdata($idmax){
        $data['idmax']=$idmax;
        $img='image/xlsx.png';
        $data['img']=$img;
        $this->load->view('bacteria/v_data',$data);
    }
    function vimage($idmax){
//        echo $total_rows;
        $data['idmax']=$idmax;

//        $this->load->model('m_bacteria');
//        $data['image'] = $this->m_bacteria->queryById($image_id);
//        print $image_id;
        $this->load->view('bacteria/v_image',$data);
    }
    function imageup(){
        $this->load->view('bacteria/v_imageup');
    }
    public function excel_out($image_id){
        header('Content-Type:application/vnd.ms-excel');
        header("Content-Disposition:attachment;filename=总表.xls");
        $this->load->model('m_bacteria');
        $array=$this->m_bacteria->download($image_id);
        $array1=$this->m_bacteria->downloadq($image_id);
        foreach($array1 as $value){
            $imagedata=$value['image_data'];
            $imagename=$value['image_name'];
        }
        $str="质合比\t"."峰高\t"."峰面积\t"."信噪比\t"."分辨率\t"."$imagename\t"."$imagedata\n";
        foreach($array as $val){
            $str.=$val['data_m_z']."\t".$val['data_peak_height']."\t".$val['data_peak_area']."\t".$val['data_signal_noise_ratio']."\t".$val['data_image_resolution']."\n";
        }
        echo $str;
    }
    public function excel_out_mz($image_id){
//        header("Content-type:text/html");
        header('Content-Type:application/vnd.ms-excel');
        header("Content-Disposition:attachment;filename=质合比.xls");
        $this->load->model('m_bacteria');
        $array=$this->m_bacteria->download($image_id);
        $array1=$this->m_bacteria->downloadq($image_id);
        foreach($array1 as $value){
            $imagedata=$value['image_data'];
            $imagename=$value['image_name'];
        }
        $str="质合比\t"."$imagename\t"."$imagedata\n";
        foreach($array as $val){
            $str.=$val['data_m_z']."\t";
        }
        echo $str;
    }
    public function excel_out_height($image_id){
//        header("Content-type:text/html");
        header('Content-Type:application/vnd.ms-excel');
        header("Content-Disposition:attachment;filename=峰高.xls");
        $this->load->model('m_bacteria');
        $array=$this->m_bacteria->download($image_id);
        $array1=$this->m_bacteria->downloadq($image_id);
        foreach($array1 as $value){
            $imagedata=$value['image_data'];
            $imagename=$value['image_name'];
        }
        $str="峰高\t"."$imagename\t"."$imagedata\n";
        foreach($array as $val){
            $str.=$val['data_peak_height']."\t";
        }
        echo $str;
    }
    public function excel_out_area($image_id){
//        header("Content-type:text/html");
        header('Content-Type:application/vnd.ms-excel');
        header("Content-Disposition:attachment;filename=峰面积.xls");
        $this->load->model('m_bacteria');
        $array=$this->m_bacteria->download($image_id);
        $array1=$this->m_bacteria->downloadq($image_id);
        foreach($array1 as $value){
            $imagedata=$value['image_data'];
            $imagename=$value['image_name'];
        }
        $str="峰面积\t"."$imagename\t"."$imagedata\n";
        foreach($array as $val){
            $str.=$val['data_peak_area']."\t";
        }
        echo $str;
    }
    public function excel_out_ratio($image_id){
//        header("Content-type:text/html");
        header('Content-Type:application/vnd.ms-excel');
        header("Content-Disposition:attachment;filename=信噪比.xls");
        $this->load->model('m_bacteria');
        $array=$this->m_bacteria->download($image_id);
        $array1=$this->m_bacteria->downloadq($image_id);
        foreach($array1 as $value){
            $imagedata=$value['image_data'];
            $imagename=$value['image_name'];
        }
        $str="信噪比\t"."$imagename\t"."$imagedata\n";
        foreach($array as $val){
            $str.=$val['data_signal_noise_ratio']."\t";
        }
        echo $str;
    }
    public function excel_out_resolution($image_id){
//        header("Content-type:text/html");
        header('Content-Type:application/vnd.ms-excel');
        header("Content-Disposition:attachment;filename=分辨率.xls");
        $this->load->model('m_bacteria');
        $array=$this->m_bacteria->download($image_id);
        $array1=$this->m_bacteria->downloadq($image_id);
        foreach($array1 as $value){
            $imagedata=$value['image_data'];
            $imagename=$value['image_name'];
        }
        $str="分辨率\t"."$imagename\t"."$imagedata\n";
        foreach($array as $val){
            $str.=$val['data_image_resolution']."\t";
        }
        echo $str;
    }
    public function toghter(){
//        header('Content-Type:application/vnd.ms-excel');
//        header("Content-Disposition:attachment;filename=总表.xls");
        $image_id = $this->input->post('mycheckbox[]');
        if(sizeof($image_id)>0){
            $str = implode(" ",$image_id);
            $data['str']=$str;
    //        echo $str;
            $this->load->view('bacteria/v_download',$data);}

    }
    public function toghterAdmin(){
        $image_id = $this->input->post('mycheckbox[]');
        if(sizeof($image_id)>0){
            $str = implode(" ",$image_id);
            $data['str']=$str;
            $this->load->view('bacteria/v_download_admin',$data);}
    }
    public function download($str){
        header('Content-Type:application/vnd.ms-excel');
        header("Content-Disposition:attachment;filename=总表批量下载.xls");
//        echo $str;
        $id = explode("%20",$str);
        $name = implode("|",$id);
//        echo $image_id[0];
//        $this->load->view('bacteria/v_success');
        for($i=0;$i<sizeof($id);$i++){
            $image_id=$id[$i];
            $this->load->model('m_bacteria');
            $array=$this->m_bacteria->download($image_id);
            $array1=$this->m_bacteria->downloadq($image_id);
            foreach($array1 as $value){
                $imagedata=$value['image_data'];
                $imagename=$value['image_name'];
            }
            $str="质合比\t"."峰高\t"."峰面积\t"."信噪比\t"."分辨率\t"."$imagename\t"."$imagedata\n";
            foreach($array as $val){
                $str.=$val['data_m_z']."\t".$val['data_peak_height']."\t".$val['data_peak_area']."\t".$val['data_signal_noise_ratio']."\t".$val['data_image_resolution']."\n";
            }
            echo $str;
            $str1="\n";
            echo $str1;
        }
//        $image_id=$image_id1[1];
//            $this->load->model('m_bacteria');
//            $array=$this->m_bacteria->download($image_id);
//            $str="分辨率\n";
//            foreach($array as $val){
//                $str.=$val['data_image_resolution']."\t";
//            }
//        echo $str;
    }
    public function download1($str){
        header('Content-Type:application/vnd.ms-excel');
        header("Content-Disposition:attachment;filename=质合比批量下载.xls");
        $id = explode("%20",$str);
        $name = implode("|",$id);
        for($i=0;$i<sizeof($id);$i++){
            $image_id=$id[$i];
            $this->load->model('m_bacteria');
            $array=$this->m_bacteria->download($image_id);
            $array1=$this->m_bacteria->downloadq($image_id);
            foreach($array1 as $value){
                $imagedata=$value['image_data'];
                $imagename=$value['image_name'];
            }
            $str="质合比\t"."$imagename\t"."$imagedata\n";
            foreach($array as $val){
                $str.=$val['data_m_z']."\t";
            }
            echo $str;
            $str1="\n";
            echo $str1;
        }
    }
    public function download2($str){
        header('Content-Type:application/vnd.ms-excel');
        header("Content-Disposition:attachment;filename=峰高批量下载.xls");
        $id = explode("%20",$str);
        $name = implode("|",$id);
        for($i=0;$i<sizeof($id);$i++){
            $image_id=$id[$i];
            $this->load->model('m_bacteria');
            $array=$this->m_bacteria->download($image_id);
            $array1=$this->m_bacteria->downloadq($image_id);
            foreach($array1 as $value){
                $imagedata=$value['image_data'];
                $imagename=$value['image_name'];
            }
            $str="峰高\t"."$imagename\t"."$imagedata\n";
            foreach($array as $val){
                $str.=$val['data_peak_height']."\t";
            }
            echo $str;
            $str1="\n";
            echo $str1;
        }
    }
    public function download3($str){
        header('Content-Type:application/vnd.ms-excel');
        header("Content-Disposition:attachment;filename=峰面积批量下载.xls");
        $id = explode("%20",$str);
        $name = implode("|",$id);
        for($i=0;$i<sizeof($id);$i++){
            $image_id=$id[$i];
            $this->load->model('m_bacteria');
            $array=$this->m_bacteria->download($image_id);
            $array1=$this->m_bacteria->downloadq($image_id);
            foreach($array1 as $value){
                $imagedata=$value['image_data'];
                $imagename=$value['image_name'];
            }
            $str="峰面积\t"."$imagename\t"."$imagedata\n";
            foreach($array as $val){
                $str.=$val['data_peak_area']."\t";
            }
            echo $str;
            $str1="\n";
            echo $str1;
        }
    }
    public function download4($str){
        header('Content-Type:application/vnd.ms-excel');
        header("Content-Disposition:attachment;filename=信噪比批量下载.xls");
        $id = explode("%20",$str);
        $name = implode("|",$id);
        for($i=0;$i<sizeof($id);$i++){
            $image_id=$id[$i];
            $this->load->model('m_bacteria');
            $array=$this->m_bacteria->download($image_id);
            $array1=$this->m_bacteria->downloadq($image_id);
            foreach($array1 as $value){
                $imagedata=$value['image_data'];
                $imagename=$value['image_name'];
            }
            $str="信噪比\t"."$imagename\t"."$imagedata\n";
            foreach($array as $val){
                $str.=$val['data_signal_noise_ratio']."\t";
            }
            echo $str;
            $str1="\n";
            echo $str1;
        }
    }
    public function download5($str){
        header('Content-Type:application/vnd.ms-excel');
        header("Content-Disposition:attachment;filename=分辨率批量下载.xls");
//        echo $str;
        $id = explode("%20",$str);
        $name = implode("|",$id);
//        echo sizeof($id);
//        $this->load->view('bacteria/v_success');
        for($i=0;$i<sizeof($id);$i++){
            $image_id=$id[$i];
            $this->load->model('m_bacteria');
            $array=$this->m_bacteria->download($image_id);
            $array1=$this->m_bacteria->downloadq($image_id);
            foreach($array1 as $value){
                $imagedata=$value['image_data'];
                $imagename=$value['image_name'];
            }
            $str="分辨率\t"."$imagename\t"."$imagedata\n";
            foreach($array as $val){
                $str.=$val['data_image_resolution']."\t";
            }
            echo $str;
            $str1="\n";
            echo $str1;
        }
    }
    public function addExcel($idmax)
    {
        //接收前台文件
        $ex = $_FILES['excel'];
        //重设置文件名
        $filename = time().substr($ex['name'],stripos($ex['name'],'.'));
        $path = 'bac_files/'.$filename;//设置移动路径
        move_uploaded_file($ex['tmp_name'],$path);
        //表用函数方法 返回数组
        $exfn = $this->_readExcel($path);
       // print_r($exfn);
        //$this->index();
        $this->load->model('m_bacteria');
        for($i=0;$i<sizeof($exfn);$i++){

            $arr = array('data_m_z'=>$exfn[$i][1],
                'data_peak_height'=>$exfn[$i][2],
                'data_peak_area'=>$exfn[$i][3],
                'data_signal_noise_ratio'=>$exfn[$i][4],
                'data_image_resolution'=>$exfn[$i][5],
                'image_id'=>$idmax);
            $insert=$this->m_bacteria->insert($arr);

            //$this->queryById($bac_id);
        }
        redirect('c_data');
    }
    public function addImageExcel()
    {
        //接收前台文件
        $ex = $_FILES['excel'];
        //重设置文件名
        $filename = time().substr($ex['name'],stripos($ex['name'],'.'));
        $path = 'image/'.$filename;//设置移动路径
        move_uploaded_file($ex['tmp_name'],$path);
        //表用函数方法 返回数组
        $exfn = $this->_readExcel($path);
        // print_r($exfn);
        //$this->index();
        $this->load->model('m_bacteria');
        for($i=1;$i<sizeof($exfn);$i++){

            $arr = array('image_path'=>$exfn[$i][1],
                'image_name'=>$exfn[$i][2]);
            $insert=$this->m_bacteria->insertimage($arr);

            //$this->queryById($bac_id);
        }
        redirect('c_data');

    }
    //创建一个读取excel数据，可用于入库
    public function _readExcel($path)
    {
        //引用PHPexcel 类
        $this->load->library('PHPExcel');
        $this->load->library('PHPExcel/IOFactory');//静态类
        $type = 'Excel2007';//设置为Excel5代表支持2003或以下版本，Excel2007代表2007版
        $xlsReader = IOFactory::createReader($type);
       // $xlsReader->setReadDataOnly(true);
        //$xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($path);
        //开始读取上传到服务器中的Excel文件，返回一个二维数组
        $dataArray = $Sheets->getSheet(0)->toArray();
        return $dataArray;
    }

}
?>